#include<iostream>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>

#define ERR_EIXT(m)\
do{\
    perror(m);\
    exit(EXIT_FAILURE);\
}while(0)

int main(){
    int fifod=open("myfifo",O_RDWR);
    if(fifod<0)
        ERR_EIXT("opening myfifo");

    char buffer[1024];
    while(1){
        buffer[0]=0;
        std::cout<<"Please write in...and push Enter to quit."<<std::endl;
        fflush(stdin);
        int s=read(0,buffer,sizeof(buffer)-1);
        if(!s){
            std::cout<<"Client stop writing and quit..."<<std::endl;
            exit(EXIT_SUCCESS);
        }
        else if(s>0){
            buffer[s]=0;
            write(fifod,buffer,sizeof(buffer)-1);
        }
        else
            ERR_EIXT("write");
    }

    return 0;
}